<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>发布博客</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" type="text/css" href="/bootstrap/bootstrap.css"/>
    <link href="/summernote-0.8.18/summernote.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/css/cms.css"/>
  </head>
  <body>
    <jsp:include page="/WEB-INF/inc/top.jsp"></jsp:include>
	
	<!-- 横幅 -->
	<div class="container">
		<div class="row">
			<div class="col-xs-12 my_banner">
			</div>
		</div>
	</div>
	<br/>
	<!-- 主体内容区 -->
	<div class="container">
		<div class="row">
			<div class="col-md-3">
				<jsp:include page="/WEB-INF/inc/my_left.jsp"><jsp:param value="blog" name="module"/></jsp:include>
			</div>
			<div class="col-md-9">
				<div class="panel panel-default">
				  <div class="panel-body">
				    	<h1>发布博客</h1>
				    	<hr/>
				    	<form id="myform" action="/my/blog/save" enctype="multipart/form-data" method="post">
							<input type="hidden" name="id" value="${article.id}">
							<p>
							<input type="text" name="title" class="form-control" placeholder="博客标题" value="${article.title}">
						    </p>
							<p>
								<textarea name="content">${article.content}</textarea>
							</p>
							<p>
								<textarea name="summary" placeholder="摘要" rows="5" style="width: 300px">${article.summary}</textarea>
							</p>
							<p>
								所属频道:<select class="form-control" name="channel.id" onchange="getCategory(this)">
								<option value="">请选择</option>
								<c:forEach items="${channels}" var="var">
									<option value="${var.id}" <c:if test="${var.id==article.channel.id}">selected</c:if> >${var.name}</option>
								</c:forEach>
							</select>


							</p>
							<p>
								所属分类:<select class="form-control" name="category.id">
								<option value="">请选择</option>
							</select>
							</p>
							<p>
								<input type="file" name="file" class="form-control" placeholder="上传封面">
								<img src="${article.picture}" id="picture" style="width: 30px;height: 30px"><br>
							</p>
							<button type="submit" class="btn btn-info btn-block">保存</button>
						</form>

				  </div>
				</div>
				
			</div>
		</div>
	</div>
	
	<jsp:include page="/WEB-INF/inc/footer.jsp"/>
	<script src="/summernote-0.8.18/summernote.js"></script>

	<script type="text/javascript">
		$("[name='content']").summernote();
		$("[name='summary']").summernote();
		/*$(document).ready(function(){
			$("[name='content']").summernote({
				placeholder:'博客内容',
				height:200
			});
			$("[name='summary']").summernote({
				placeholder:'摘要',
				height:200
			});
		});*/
		function getCategory(obj) {
			let channelId = $(obj).val();
			$.post("/my/getCategories?channelId="+channelId,function (res) {
				$('[name="category.id"]').html('<option value="">请选择</option>');
				for (let x in res) {
					$('[name="category.id"]').append('<option value="'+res[x].id+'">'+res[x].name+'</option>')
				}

			})

		}
	</script>
  </body>
</html>